Test Series - java script

Test Number 82/92

Q: Which of the following is one of the fundamental features of JavaScript?
A. Single-threaded
B. Multi-threaded
C. Both Single-threaded and Multi-threaded
D. Simple-threaded
Solution: In computer programming, single-threading is the processing of one command at a time. One of the fundamental features of client-side JavaScript is that it is single-threaded: a browser will never run two event handlers at the same time, and it will never trigger a timer while an event handler is running.
Q: Which of the following functions are synchronous?
A. load()
B. require()
C. both load() and require()
D. create()
Solution: JavaScript has two synchronous load() and require(). The load() method loads data from a server and puts the returned data into the selected element.
Q: Why shouldn’t JavaScript functions not be too long?
A. User friendliness
B. Tie up event loops
C. Browser becomes unresponsive
D. All of the mentioned
Solution: When JavaScript code runs for longer than a predefined amount of time than the browser shows a message of unresponsive script. The client-side JavaScript functions must not run too long: otherwise, they will tie up the event loop and the web browser will become unresponsive to user input.
Q: The object that looks to the thread that creates it is _______________
A. Window
B. Worker
C. Element
D. Hash
Solution: A web worker is a JavaScript running in the background, without affecting the performance of the page. The Worker object: this is what a worker looks like from the outside to the thread that creates it.
Q: Which of the following is a global object for a new worker?
A. WorkerGlobalScope
B. Worker
C. WorkerScope
D. Window
Solution: A web worker is a JavaScript that runs in the background, independently of other scripts, without affecting the performance of the page. The WorkerGlobalScope is the global object for a new worker, and it is what a worker thread looks like, on the inside, to itself.
Q: Which will be invoked to create a new worker?
A. Function
B. Destructor
C. Constructor
D. Interface
Solution: When executing scripts in an HTML page, the page becomes unresponsive until the script is finished. To create a new worker, just use the Worker() constructor, passing a URL that specifies the JavaScript code that the worker is to run :
var loader = new Worker("utils/loader.js");
Q: What will happen if you specify an absolute URL in the Worker constructor?
A. Resolves itself
B. Must have the same origin
C. Must not have the same origin
D. Specify the address
Solution: If you specify an absolute URL, it must have the same origin (same protocol, host, and port) as that containing document. In Firefox, if you want to use workers in extensions and would like to have access to js-ctypes, you should use the ChromeWorker object instead.
Q: How can you send data using a Worker object?
A. postMessage()
B. sendMessage()
C. Message()
D. post()
Solution: Once you have a Worker object, you can send data to it with postMessage(). The value you pass to postMessage() will be cloned, and the resulting copy will be delivered to the worker via a message event. postMessage() sends a message — which can consist of any JavaScript object — to the worker’s inner scope.
loader.postMessage("file.txt");
Q: Which property is used to manage multiple event handlers?
A. onmessage
B. onerror
C. both onmessage and onerror
D. postmessage
Solution: message event is fired when the worker’s parent receives a message from its worker which is also available via the onmessage property. You can use onmessage and onerror properties if you want to manage multiple event handlers.
Q: Which is the function that allows a worker to terminate itself?
A. close()
B. exit()
C. terminate()
D. halt()
Solution: Worker.terminate() Immediately terminates the worker. This does not offer the worker an opportunity to finish its operations. The close() function allows a worker to terminate itself, and it is similar in effect to the terminate() method of a Worker object.

You Have Score    /10